/*
 * @Descripttion: 
 * @version: 
 * @Author: turingchang
 * @Date: 2020-08-28 16:08:51
 * @LastEditors: turingchang
 * @LastEditTime: 2020-09-08 14:59:54
 */

const Service = require('egg').Service;

class AdminService extends Service {
    async list() {
        const admin_list = await this.ctx.model.Admin.Admin.findAndCountAll({
            attributes: { exclude: ['delete_time','roleId']},
            // include: {
            //     model: this.ctx.app.model.Admin.Role,
            //     include: {
            //         model: this.ctx.app.model.Admin.Permission,                    
            //     },
            // },
            limit: this.ctx.limit,
            offset: this.ctx.offset,
            distinct: true,
            subQuery:false,
        });
        return admin_list;
    }
    async get(id) {
        const admin = await this.ctx.model.Admin.Admin.findOne({
            attributes: { exclude: ['delete_time','roleId']},
            include: {
                model: this.ctx.app.model.Admin.Role,
                include: {
                    model: this.ctx.app.model.Admin.Permission,                    
                },
                where:{
                    status:this.ctx.app.enums.status.normal.value
                },
            },
            where:{
                id:id,
                status:this.ctx.app.enums.status.normal.value
            }
        });
        if(this.ctx.app.utils.validator.isNull(admin)){
            return null;
        }
        await this.ctx.service.home.home.formatAntRolePermissions(admin);
        return admin;
    }
    async create(admin) {
        const res = await this.ctx.model.Admin.Admin.create(admin);
        return res;
    }

    async info() {
        const admin = this.ctx.user;
        return admin;
    }

    async menuList(){
        
    }
    
  
}

module.exports = AdminService;